home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Papers / Downs.FileSystem / source / notification / Callbacks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-24  |  1.7 KB  |  67 lines  |  [TEXT/CWIE]

  1. #include "Callbacks.h"
  2.  
  3.  
  4. // Ignore first two params to CallUniversalProc().
  5. asm void        PrologGlue() {
  6.     addi        sp, sp, 0x08
  7.     blr
  8. }
  9.  
  10. // Restore first two params to CallUniversalProc().
  11. asm void        EpilogGlue() {
  12.     subi        sp, sp, 0x08
  13.     blr
  14. }
  15.  
  16. pascal    void        MyCreateCallback( FWData theFWData )
  17. {
  18.     PrologGlue();
  19.     
  20.     // Do something with incoming data...
  21.     //HandleCreate( theFWData );
  22.  
  23.     EpilogGlue();
  24. }
  25.                         
  26. void    Subscribe() {
  27.     OSErr    theErr = noErr;
  28.     SelectorFunctionUPP    myGestaltUPP;
  29.     FWSubscribePtr    theFWSubscribePtr;            
  30.  
  31.     theErr = ::Gestalt( FS_SIGNATURE, ( long * )&myGestaltUPP );
  32.  
  33.     if ( theErr == noErr ) {
  34.         //::DebugStr( "\pRemoving callback address from extension..." );
  35.         
  36.         theFWSubscribePtr = ( FWSubscribePtr )NewPtr( sizeof( FWSubscribe ) );
  37.         
  38.         if ( theFWSubscribePtr != nil ) {
  39.             theFWSubscribePtr->theAction = kCreateFlag;
  40.             theFWSubscribePtr->theCallbackAddr = ( long * )&MyCreateCallback;
  41.             theErr = CallSelectorFunctionProc( myGestaltUPP, GESTALT_ADD_CALLBACK, ( long * )theFWSubscribePtr );
  42.             DisposePtr( ( Ptr )theFWSubscribePtr );
  43.         }
  44.     }
  45. }
  46.  
  47. void    Unsubscribe() {
  48.     OSErr    theErr = noErr;
  49.     SelectorFunctionUPP    myGestaltUPP;
  50.     FWSubscribePtr    theFWSubscribePtr;            
  51.  
  52.     theErr = ::Gestalt( FS_SIGNATURE, ( long * )&myGestaltUPP );
  53.  
  54.     if ( theErr == noErr ) {
  55.         //::DebugStr( "\pRemoving callback address from extension..." );
  56.         
  57.         theFWSubscribePtr = ( FWSubscribePtr )NewPtr( sizeof( FWSubscribe ) );
  58.         
  59.         if ( theFWSubscribePtr != nil ) {
  60.             theFWSubscribePtr->theAction = kCreateFlag;
  61.             theFWSubscribePtr->theCallbackAddr = ( long * )&MyCreateCallback;
  62.             theErr = CallSelectorFunctionProc( myGestaltUPP, GESTALT_REMOVE_CALLBACK, ( long * )theFWSubscribePtr );
  63.             DisposePtr( ( Ptr )theFWSubscribePtr );
  64.         }
  65.     }
  66. }
  67.